import axios from "axios";

/**@description 获取文件源码 */
export const getFileRaw = (path, branch = "master") => {
  return new Promise((resolve, reject) => {
    axios
      .get("http://localhost:3000/readerRaw", {
        params: {
          path,
          branch_name: branch,
        },
      })
      .then((res) => {
        resolve(res.data);
      })
      .catch((error) => {
        reject(error);
      });
  });
};

/**
 * @description   更新文件源码
 * @param {*} content
 * @param {*} sha
 * @param {*} path
 * @param {string} message
 * @returns
 */
export const updateFileRaw = (content, branch, sha, path, message) => {
  return new Promise((resolve, reject) => {
    axios
      .put("http://localhost:3000/updateRow", {
        content,
        branch,
        sha,
        path,
        message,
      })
      .then((res) => {
        resolve(res.data);
      })
      .catch((error) => {
        reject(error);
      });
  });
};

// /**@description 创建分支 */
// export const createPushRequest = (branch_name) => {
//   return new Promise((resolve, reject) => {
//     axios
//       .post("http://localhost:3000/createBranch", {
//         branch_name,
//       })
//       .then((res) => {
//         resolve(res.data);
//       })
//       .catch((error) => {
//         reject(error);
//       });
//   });
// };
